package com.lht.arithmetic.tree.binaryTree.avl;

import java.util.*;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-11-21
 */
public class MyAVLTreeDemo {

    public static void main(String[] args) {
        MyAvlTree<Student> studentMyAvlTree = new MyAvlTree<>();

        Random random = new Random();
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            students.add(new Student(i, UUID.randomUUID().toString(), random.nextInt(750)));
        }
        for (Student s : students) {
            studentMyAvlTree.add(s);
        }

        // 中序遍历出来
        List<Integer> scores = new ArrayList<>();
        middle(studentMyAvlTree.getRoot(), scores);
        scores.forEach(s -> System.out.println(s));
        for (Student s : students) {
            Student q = studentMyAvlTree.search(s);
        }

//        for (int i =2; i <999; i++ ) {
//            Student s = students.get(i);
//            studentAvlTree.remove(s);
//        }
//        System.out.println(JSON.toJSONString(studentAvlTree));
    }

    public static void middle(MyAvlTree.AvlNode<Student> treeNode, List<Integer> score) {
        if (treeNode.getLeft() == null) {
            return;
        } else {
            middle(treeNode.getLeft(), score);
        }
        if (null != treeNode.getLeft()) {
            score.add(treeNode.getLeft().getElement().getTotalScore());
        }
        score.add(treeNode.getElement().getTotalScore());
        if (null != treeNode.getRight()) {
            score.add(treeNode.getRight().getElement().getTotalScore());
        }
    }

}

